<template>
        <el-card shadow="never" style="max-height: 70vh; overflow: auto">
            <el-form ref="form" :model="form" :rules="rules" label-width="90px" :disabled="disabled">
                <el-form-item label="账号:" prop="account">
                    <el-input v-model="form.account" placeholder="请输入账号" clearable autocomplete="new-password" />
                </el-form-item>
                <el-form-item label="昵称:" prop="nickname">
                    <el-input v-model="form.nickname" placeholder="请输入昵称" clearable autocomplete="new-password" />
                </el-form-item>
                <el-form-item label="密码:" prop="pwd">
                    <el-input v-model="form.pwd" placeholder="请输入密码" type="password" clearable autocomplete="new-password" />
                </el-form-item>
                <el-form-item label="状态:" prop="status">
                    <el-select v-model="form.status" placeholder="请选择状态" clearable>
                        <el-option v-for="(item, index) in status" :key="index" :label="item.label" :value="item.value" />
                    </el-select>
                </el-form-item>
                <el-form-item label="电话:" prop="phone">
                    <el-input v-model="form.phone" placeholder="请输入电话" clearable />
                </el-form-item>
                <el-form-item label="头像:" prop="avatar">
                    <ImageUpload v-model="form.avatar" />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm">确认 </el-button>
                    <el-button type="warning" @click="cancel">取消 </el-button>
                </el-form-item>
            </el-form>
        </el-card>
</template>
<script>
import { regionData } from 'element-china-area-data'
export default {
    name: 'EditForm',
    props: {
        findFormData: {
            type: Object,
            default: {}
        },
        editFormParams: {
            type: Object,
            default: {}
        },
        // 表单是否禁用
        disabled: {
            type: Boolean,
            default: false,
        },
    },
    data() {
        return {
            // 编辑表单验证规则
            rules: {
                uid: [{ required: true, message: "请输入用户ID", trigger: "blur" }],
                spread_uid: [{ required: true, message: "请输入spread_uid", trigger: "blur" }],
                agent_id: [{ required: true, message: "请输入agent_id", trigger: "blur" }],
                status: [{ required: true, message: "请输入状态", trigger: "blur" }],
                created_at: [{ required: true, message: "请输入注册时间", trigger: "blur" }],
                updated_at: [{ required: true, message: "请输入更新时间", trigger: "blur" }],
                type: [{ required: true, message: "请输入类型", trigger: "blur" }],
            },
            form: {  },
            // 区域选择配置
            areaOptions: regionData,
            status:[
               { label: "启用", value: 1 },
               { label: "禁用", value: 2 },
            ],
            type:[
               { label: "普通用户", value: 1 },
               { label: "管理员", value: 2 },
               { label: "代理", value: 3 },
            ],
            gender:[
               { label: "未知", value: 0 },
               { label: "男", value: 1 },
               { label: "女", value: 2 },
            ],
        }
    },
    watch: {
        findFormData: {
           handler(nval) {
                if (JSON.stringify(nval) !== '{}') {
                    this.$nextTick(() => {
                        this.form = nval
                        this.form.pwd = ''
                    })
                }
            },
            immediate: true,
            deep: false,
        },
    },
    methods: {
        // 取消按钮
        cancel() {
            this.$emit('editFormCancel')
        },
        submitForm() {
            this.$refs['form'].validate((valid, obj) => {
                if (valid) {
                    this.$emit('submitForm', this.form)
                }
            })
        },
        // 表单重置
        reset() {
            this.resetForm('form')
        }
    }
}
</script>
